<?php
namespace common\util;

/**
 * 实现单例模式
 * @author 王金喜
 */
trait Instance {
    protected static $_instanceList = [];
    
    public final static function instance() {
        $className = get_called_class();
        if (!isset(self::$_instanceList[$className])) {
            $instance = new static();
            self::$_instanceList[$className] = $instance;
            return $instance;
        }
        return self::$_instanceList[$className];
    }
    
}
